<?php

namespace App\Services\Cache;

use App\Models\Product;
use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\Api\V1\Queries\CommentQuery;

class CommentCache
{
	
	public function comments(Product $product)
	{
		$key = url()->full();
		$comments = Cache::remember($key, 1, function () use ($product) {
			$comments = app(CommentQuery::class)
				->where('commentable_id', $product->id)
				->where('commentable_type', Product::class)
				->paginate();
			return $comments;
		});
		return $comments;
	}
}
